home *** CD-ROM | disk | FTP | other *** search
/ Aminet 8 / Aminet 8 (1995)(GTI - Schatztruhe)[!][Oct 1995].iso / Aminet / util / cli / iuw_clitools.lha / src / exec.c < prev    next >
C/C++ Source or Header  |  1995-09-05  |  2KB  |  93 lines

  1. /* exec
  2.  *
  3.  * Copyright (C) 1995 by Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de)
  4.  *
  5.  * Permission to use, copy, modify, and distribute this software and its
  6.  * documentation for any purpose and without fee is hereby granted, provided
  7.  * that the above copyright notice appear in all copies and that both that
  8.  * copyright notice and this permission notice appear in supporting
  9.  * documentation.  This software is provided "as is" without express or
  10.  * implied warranty.
  11.  *
  12.  * V1.0: 23/Aug/95: first version
  13.  */
  14. #define THIS_PROGRAM    "exec"
  15. #define THIS_VERSION    "1.0"
  16.  
  17. #include <exec/types.h>
  18. #include <exec/libraries.h>
  19. #include <dos/dostags.h>
  20. #include <stdlib.h>
  21.  
  22. #define SysBase_DECLARED
  23. #include <proto/exec.h>
  24. #include <proto/dos.h>
  25.  
  26. extern struct Library *         SysBase;
  27.  
  28. static const char amiga_version[] = "\0$VER: " THIS_PROGRAM " " THIS_VERSION " (" __COMMODORE_DATE__ ")";
  29.  
  30. const char Template[] = "STACK/K/N,PRI=PRIORITY/K/N,IGNORE/K/N,SYSSHELL/S,CMD=COM=COMMAND/A/F";
  31. __aligned struct {
  32.     LONG *  stacksize;
  33.     LONG *  priority;
  34.     LONG *  ignore;
  35.     LONG    sysshell;
  36.     STRPTR  command;
  37. } Args;
  38.  
  39. static struct TagItem tags[] = {
  40.     { SYS_UserShell,    TRUE },
  41.     { TAG_IGNORE,       TRUE },
  42.     { TAG_IGNORE,       TRUE },
  43.     { TAG_END,          TRUE }
  44. };
  45.  
  46.  
  47. void
  48. _main()
  49. {
  50.     struct RDArgs *rdargs;
  51.     LONG rc, err = 0;
  52.  
  53.     if( SysBase->lib_Version < 37 ) {
  54.         #define MESSAGE "requires AmigaOS 2.04 or higher\n"
  55.         Write(Output(), MESSAGE, sizeof(MESSAGE)-1);
  56.         _exit(RETURN_FAIL);
  57.         #undef MESSAGE
  58.     }
  59.  
  60.     if( rdargs = ReadArgs(Template, (LONG *)&Args, NULL) ) {
  61.         if( Args.sysshell )
  62.             tags[0].ti_Data = FALSE;
  63.         if( Args.stacksize ) {
  64.             tags[1].ti_Tag = NP_StackSize;
  65.             tags[1].ti_Data = *Args.stacksize;
  66.         }
  67.         if( Args.priority ) {
  68.             tags[2].ti_Tag = NP_Priority;
  69.             tags[2].ti_Data = *Args.priority;
  70.         }
  71.  
  72.         rc = SystemTagList(Args.command, tags);
  73.         if( rc < 0 ) {
  74.             err = IoErr();
  75.             rc = RETURN_FAIL;
  76.         }
  77.         FreeArgs(rdargs);
  78.     }
  79.     else {
  80.         err = IoErr();
  81.         rc = RETURN_FAIL;
  82.     }
  83.  
  84.     if( err )
  85.         PrintFault(err, THIS_PROGRAM);
  86.  
  87.     if( Args.ignore && rc <= *Args.ignore )
  88.         rc = RETURN_OK;
  89.  
  90.     _exit(rc);
  91. }
  92.  
  93.